var TEST_PROVIDER_ID = 'testProvider';
var providerManager = Context.providerManager;
var provider = Context.newProvider();
provider.providerService.initFunc = init;
providerManager.registerProvider(TEST_PROVIDER_ID, provider);

function init(provider) {
	var providerDescriptor = provider.providerDescriptor;
	var providerService = provider.providerService;
	providerDescriptor.name = 'name';
	providerService.updateFunc = update;
}

function update(provider) {
	var httpService = Context.httpService;
	var userAccount = Context.userAccount;
	httpService.navigationUrl = 'https://mano.labas.lt/lt/selfcare?auth';
	httpService.addParam('data[username]', userAccount.user.login);
	httpService.addParam('data[password]', userAccount.user.password);
	httpService.addParam('data[ref]', '');
	httpService.post();
	httpService.navigationUrl = 'https://mano.labas.lt/lt/selfcare/services/';
	var reader = httpService.get();
	var out = Context.stream;
	var line = '';
	while (line = reader.readLine()) {
		if (line.contains("Likutis:")) {
			var likutis = line.replace("Likutis: <strong>", "");
			userAccount.user.left = likutis.replace("</strong>", "");
		}
		if (line.contains(", numeris iki: ")) {
			var galioja = line.split("<..?>");
			userAccount.user.validTo = galioja[2];
			userAccount.user.numbValidTo = galioja[4];
		}
	}
	reader.close();
}